package bai.myworld.controller.user;


import bai.myworld.common.utils.JwtUtil;
import bai.myworld.common.utils.Result;
import bai.myworld.pojo.vo.user.AuthVO;
import bai.myworld.pojo.dto.user.LoginDTO;
import bai.myworld.pojo.dto.user.RegisterDTO;
import bai.myworld.service.impl.user.UserService;
import jakarta.validation.Valid;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/user")
public class UserController {
    private static final Logger log = LogManager.getLogger(JwtUtil.class); // 修复日志记录器

    @Autowired
    private UserService userService;

    @PostMapping("/register")
    public Result<AuthVO> register(@RequestBody @Valid RegisterDTO registerDTO) {
        AuthVO authVO = userService.register(registerDTO);
        return Result.success(authVO, "注册成功");
    }

    @PostMapping("/login")
    public Result<AuthVO> login(@Valid @RequestBody LoginDTO dto) {
        AuthVO authVO = userService.login(dto);
        return Result.success(authVO, "登录成功");
    }


}
